package org.anachronos.jeep.core.trace.impl;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlType;

@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class NamedElement {
	@XmlAttribute(required=true)
	private String name;

	@XmlAttribute(required=true)
	@XmlID
	private String id;
	
	/**
	 * Required by jaxb.
	 */
	public NamedElement() {	
	}
	
	public NamedElement(final String name, final String id) {
		this.name = name;
		this.id = id;
	}

	public void setName(final String name) {
		this.name = name;
	}
	
	public void setId(final String id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}

	public String getId() {
		return id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NamedElement other = (NamedElement) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}